<template>
	<view></view>
</template>

<script>
//引入腾旭地图sdk
import qqmapsdk from './js/qqmap-wx-jssdk.js';
const QQMapWX = new qqmapsdk({
	key: 'BZIBZ-GU6LV-FBLPG-UX53W-IPPW2-IEFXI' //开发者密钥 腾讯地图key
});
export default {
	name: 'mapInfo',
	data() {
		return {
			addressDetails: '', // 地址详情
			id: 0, // 使用 marker点击事件 需要填写id
			title: 'map',
			latitude: 39.909,
			longitude: 116.39742,
			scale: 16,
			markers: [
				{
					id: 0,
					// width: 23, //宽
					// height: 35, //高
					title: '我在这里', //标注点名
					latitude: 39.909,
					longitude: 116.39742,
					iconPath: ''
				}
			]
		};
	},
	// 比onload更早
	onReady(e) {
		console.log('前页面传过来的数据------', e);
		this.openMap()
	},
	methods: {
		// 打开地图
		openMap() {
			let that = this;
			uni.showLoading({
				title: '加载中'
			});
			uni.getLocation({
				type: 'gcj02', //返回可以用于uni.openLocation的经纬度
				success: function(res) {
					console.log('获取当前地址的信息-----', res);
					that.latitude = res.latitude;
					that.longitude = res.longitude;
					that.markers[0].latitude = res.latitude;
					that.markers[0].longitude = res.longitude;
					// 解析地址
					QQMapWX.reverseGeocoder({
						location: {
							latitude: res.latitude,
							longitude: res.longitude
						},
						success: function(res) {
							// console.log(res);
							that.addressDetails = res.result.address;
						},
						fail: function(res) {
							uni.showToast({
								title: '定位失败',
								duration: 2000,
								icon: 'none'
							});
							console.log(res);
						}
					});
					uni.hideLoading();
				}
			});
		},
	}
};
</script>

<style lang="scss" scoped></style>
